<?php
    if($this->unknownError == true) {
        echo $this->view->flashMessage()->renderMessage('En ukjent feil oppstod', RedCross_View_Helper_FlashMessage::ERROR);
    }
    
    echo $this->flashMessage()->renderMessages(); 
?>

<?php 
    if ($this->course->type == 'course'):
        $expertise_type = 'kurs';
    else:
        $expertise_type = 'kompetanse';
    endif;

    $this->pageHeader('Rediger ' . $expertise_type);
?>


<?php
    $isCourseArchived = !is_null($this->course->archived_date);
?>

<!--h1>Rediger <?php echo $expertise_type; ?>: <?php echo $this->escape($this->course->name); ?> <?php echo $isCourseArchived ? '(arkivert)' : ''; ?></h1-->

<?php
$this->editForm->setMethod('post');
$this->editForm->setAction($this->url());
echo $this->editForm;
?>

<?php #<h2>Medlemmer med echo $this->course->name </h2>?>
<div class="header_wrapper">
    <h1>Medlemmer</h1>
    <?php echo $this->filterForm; ?>
</div>

<form id="add_course_to_members" method="post" action="<?php echo $this->url(array('module' => 'admin', 'controller' => 'course', 'action' => 'add-members'), null, false); ?>">

<table id="course_members">
    <thead>
        <tr>
            <th>&nbsp;</th>
            <th>Navn</th>
            <th>Utløpsdato</th>
        </tr>
    </thead>
    <tbody>
    <?php foreach ($this->members as $member): ?>
    <?php
    $courseInfo = null;
    foreach ($member->MemberCourse as $memberCourse):
        if ($memberCourse->course_id == $this->course->id):
            $courseInfo = $memberCourse;
        endif;
    endforeach;
    ?>
        <tr>
            <td class="checkbox"><input type="checkbox" id="member_<?php echo $member->id; ?>" name="members[]" value="<?php echo $member->id ?>" /></td>
            <td><label for="member_<?php echo $member->id; ?>"><?php echo $this->escape($member->first_name . ' ' . $member->last_name); ?></label></td>
            <td>
                <?php
                    if ($courseInfo != null):
                        if ($courseInfo->expires_date != null):
                            $toDate = new RedCross_Date();
                            $toDate->import($courseInfo->expires_date);
                            echo $this->escape($toDate->getDateStr());
                        else:
                            ?> &#8734; <?php
                        endif;
                    endif;
                ?>
            </td>
        </tr>
    <?php endforeach; ?>
    </tbody>
</table>

<?php
    $filter = $this->filterForm ->getValue('filter');
    if ($filter === "not_course" || $filter === "all"):?>
        <input type="hidden" value="add_members_to_course" name="action" />
        <label class="required" for="course_date">Dato:</label><input type="text" name="course_date" id="course_date" value="<?php $today = new RedCross_Date (); echo $today->getDateStr(); ?>" />&nbsp;
        <input type="submit" value="Legg til valgte" class="positive" name="add_members_to_course" />
<?php endif;
      if ($filter === "has_course" || $filter === "all" || $filter === ""):?>
        <input type="hidden" value="remove_members_from_course" name="action" />
        <input type="submit" value="Fjern valgte" class="negative" name="remove_members_from_course" />
<?php endif?>
</form>

<p>&nbsp;</p>
